﻿using MediatR;
using WarehouseManagement.Application.Command.WarehouseCommand;
using WarehouseManagement.Infrstructre.Interface;

namespace WarehouseManagement.Application.CommandHandler.WarehouseCommandHandler
{
    /// <summary>
    /// 仓库信息删除
    /// </summary>
    public class WarehouseDelCommandHandler : IRequestHandler<WarehouseDelCommand, int>
    {
        private readonly IWarehouseRepository _warehouseRep;
        public WarehouseDelCommandHandler(IWarehouseRepository warehouseRep)
        {
            this._warehouseRep = warehouseRep;
        }

        public async Task<int> Handle(WarehouseDelCommand request, CancellationToken cancellationToken)
        {
            var res = (await _warehouseRep.GetAll()).Where(x => request.WarehouseId.Contains(x.WarehouseId)).ToList();
            foreach (var item in res)
            {
                item.IsDel = true;
                item.DelName = request.DelName;
                item.DelTime = DateTime.Now;
                await _warehouseRep.UpdateAsync(item);
            }
            return 1;
        }
    }
}
